<template>
  <div style="width: 100%" v-show="show">
    <el-collapse v-model="activeName">
      <el-collapse-item title="关系" name="1">
        <avue-crud :option="option"
                   :table-loading="loading"
                   :data="tableData"
                   ref="crud">
        </avue-crud>
      </el-collapse-item>
      <el-collapse-item title="继承的关系" name="2">
        <avue-crud :option="option"
                   :table-loading="loading"
                   :data="tableData_"
                   ref="crud">
        </avue-crud>
      </el-collapse-item>
    </el-collapse>
  </div>
</template>

<script>
import * as api from "@/api/modulManage/entity";
import index from "./index"

export default {
  name: "Relation",
  mixins: [index],
  data() {
    return {
      tableData: [],
      tableData_: [],
      activeName: ["1", "2"],
      loading: false,
      option: {
        height: '300px',
        calcHeight: 30,
        dialogWidth: 900,
        tip: false,
        searchShow: true,
        searchMenuSpan: 6,
        border: true,
        index: false,
        selection: false,
        labelWidth: 120,
        viewBtn: false,
        dialogClickModal: false,
        tabs: true,
        delBtn: false,
        addBtn: false,
        editBtn: false,
        refreshBtn: false,
        columnBtn: false,
        align: "left",
        menu: false,
        header: false,
        column: [
          {
            label: '关系英文名称',
            prop: 'nameEn',
            overHidden: true,
          },
          {
            label: "关系中文名称",
            prop: "nameCn",
            overHidden: true,
          },
          {
            label: "Form实体中文名称",
            prop: "fromTypeNameCn",
            overHidden: true,
          },
          {
            label: "To实体中文名称",
            prop: "toTypeNameCn",
            overHidden: true,
          },
          {
            label: "关系类型",
            prop: "refType",
            dicData: [
              {
                label: "一对一",
                value: "1",
              },
              {
                label: "一对多",
                value: "2",
              },
              {
                label: "多对多",
                value: "3",
              },
            ]
          },
          {
            label: "是否树形",
            prop: "isTree",
            dicData: [
              {
                label: "是",
                value: 1,
              },
              {
                label: "否",
                value: 0,
              },
            ]
          }
        ]
      },
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 1
      },
    }
  },
  methods: {
    getRelationList() {
      api.getRelationList({typeName: this.formDataAll.name}).then(res => {
        this.tableData = res.data.data;
      })
    }
  },
  watch: {
    show: {
      handler(v) {
        if (v) {
          this.getRelationList();
        }
      },
      deep: true,
      immediate: true
    }
  }
}
</script>
